package Gather.ArrayGatherExercise;

import java.util.ArrayList;

/**
 * ClassName:ArrayList004
 * Package:StringJoiner
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/17-23:59
 * @Version:v1.0
 */
public class ArrayList004 {
    /*
     * 需求：定义一个集合,添加数字,并进行遍历
     * 遍历格式：[元素1,元素2,元素3]*/

    //基本数据类型对应的包装类
    //byte--->Byte
    //short--->Short
    //char--->Character
    //int--->Integer

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        System.out.println(list);
        //遍历
        System.out.print("[");
        for (int i = 0; i < list.size(); i++) {
            if (i== list.size()-1){
                System.out.print(list.get(i));
            }else {
                System.out.print(list.get(i)+",");
            }
        }
        System.out.println("]");
    }
}
